package io.lkt.modules.sys.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.lkt.common.util.Query;
import io.lkt.common.validator.ValidatorUtils;
import io.lkt.modules.sys.entity.PeriodEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.lkt.modules.sys.entity.BSysUserWeekScoreEntity;
import io.lkt.modules.sys.service.BSysUserWeekScoreService;
import io.lkt.common.utils.PageUtils;
import io.lkt.common.utils.R;



/**
 * 系统用户积分
 *
 * @author xss
 * @email dustwas@163.com
 * @date 2021-09-08 09:30:30
 */
@RestController
@RequestMapping("/sys/bsysuserweekscore")
public class BSysUserWeekScoreController {
    @Autowired
    private BSysUserWeekScoreService bSysUserWeekScoreService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:bsysuserweekscore:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bSysUserWeekScoreService.queryPage(params);

        return R.ok().put("page", page);
    }

    @RequestMapping("/getList")
    public R getList(@RequestParam Map<String, Object> params) {
        Query query = new Query(params);
        List<BSysUserWeekScoreEntity> list = bSysUserWeekScoreService.getList(query);
        int total = bSysUserWeekScoreService.getListTotal(query).intValue();
        PageUtils page = new PageUtils(list, total, query.getLimit(), query.getPage());

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:bsysuserweekscore:info")
    public R info(@PathVariable("id") Integer id){
        BSysUserWeekScoreEntity bSysUserWeekScore = bSysUserWeekScoreService.getById(id);

        return R.ok().put("bSysUserWeekScore", bSysUserWeekScore);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:bsysuserweekscore:save")
    public R save(@RequestBody BSysUserWeekScoreEntity bSysUserWeekScore){
        bSysUserWeekScoreService.save(bSysUserWeekScore);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:bsysuserweekscore:update")
    public R update(@RequestBody BSysUserWeekScoreEntity bSysUserWeekScore){
        ValidatorUtils.validateEntity(bSysUserWeekScore);
        bSysUserWeekScoreService.updateById(bSysUserWeekScore);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:bsysuserweekscore:delete")
    public R delete(@RequestBody Integer[] ids){
        bSysUserWeekScoreService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @RequestMapping("/periodList")
    public R periodList() {
        List<PeriodEntity> periodList = bSysUserWeekScoreService.getPeriodList();
        return R.ok().put("periodList", periodList);
    }
}
